package com.lsongh.springboot2.service;

import com.lsongh.springboot2.entity.Exam;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface CheckService extends JpaRepository<Exam,Integer> {

    @Query("SELECT  a  from  Exam a  WHERE a.checkModelType = ?1 ORDER BY a.checkId DESC ")
    List<Exam> findChecks(String modelType);

    @Query("select a from Exam a  where a.checkModelType = ?1 and a.checkUsername  like concat('%' ,?2 , '%')  order by a.checkId desc ")
    List<Exam> findChecksByName(String model, String name);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query("update Exam as a set a.checkType = ?1 where a.checkId = ?2")
    void updateCheckType(Integer type,Integer id);


}
